package cn.cuiliangpeng.system.controller;



import cn.cuiliangpeng.basic.utils.PageList;
import cn.cuiliangpeng.basic.utils.AjaxResult;
import cn.cuiliangpeng.system.domain.Systemdictionarydetail;
import cn.cuiliangpeng.system.query.SystemdictionarydetailQuery;
import cn.cuiliangpeng.system.service.ISystemdictionarydetailService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Systemdictionarydetail")
public class SystemdictionarydetailController {
    @Autowired
    private ISystemdictionarydetailService iSystemdictionarydetailService;

    /**
     * 查询单个数据
     * @param id
     * @return
     */
    //get http://localhost:8080/Systemdictionarydetail/1
    @GetMapping("/{id}")
    public Systemdictionarydetail findById(@PathVariable("id") Long id){
        return iSystemdictionarydetailService.findById(id);
    }

    /**
     * 查询所有
     * @return
     */
    //get http://localhost:8080/Systemdictionarydetail
    @GetMapping
    public List<Systemdictionarydetail> findAll(){
        return iSystemdictionarydetailService.findAll();
    }

    /**
     * 分页查询
     * @param SystemdictionarydetailQuery
     * @return
     */
    //post http://localhost:8080/Systemdictionarydetail
    @PostMapping
    public PageList<Systemdictionarydetail> queryPage(@RequestBody SystemdictionarydetailQuery SystemdictionarydetailQuery){
        return iSystemdictionarydetailService.queryPage(SystemdictionarydetailQuery);
    }

    /**
     * 删除单个对象
     * @param id
     * @return
     */
    //delete  http://localhost/Systemdictionarydetail/1
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        try {
            iSystemdictionarydetailService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me();
        }
    }

    @PutMapping
    public AjaxResult addAndUpdate(@RequestBody Systemdictionarydetail Systemdictionarydetail){
        try {
            if (Systemdictionarydetail.getId()==null){
                iSystemdictionarydetailService.save(Systemdictionarydetail);
            }else {
                iSystemdictionarydetailService.update(Systemdictionarydetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me();
        }
    }

    @PatchMapping
    @ApiOperation(value = "批量删除对象")
    public AjaxResult patch(@RequestBody Long[] ids) {
        try {
            iSystemdictionarydetailService.patch(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me();
        }
    }
    @GetMapping("/type/{id}")
    public List<Systemdictionarydetail> findByIdType(@PathVariable("id") Long id){
        return iSystemdictionarydetailService.findByIdType(id);

    }
}
